/*-----------------------------------------------File Info------------------------------------------------
** File Name:               bspGpio.c  
** Last modified date:      2016.07.22
** Last version:            V0.1
** Description:             
**--------------------------------------------------------------------------------------------------------            
** Created date:            2016.09.07
** author:                  YLY
** Version:                 V0.1
** Descriptions:            gpio
**--------------------------------------------------------------------------------------------------------
*/
#include "bspGPIO.h"
#include "bspConfig.h"


void gpioConfig(tsCfgGpio *cfg)
{
    /* enable clock */
    rcu_periph_clock_enable(cfg->gpioRcu);

	gpio_bit_write(cfg->gpioPeriph, cfg->pin, cfg->value);
	
    /* connect port to cfg */
    gpio_af_set(cfg->gpioPeriph, cfg->af, cfg->pin);
    gpio_mode_set(cfg->gpioPeriph, cfg->mode, cfg->pull, cfg->pin);
    gpio_output_options_set(cfg->gpioPeriph, cfg->otype, cfg->speed, cfg->pin);
}


/* write data to the specified GPIO pin */
void gpioWrite(tsCfgGpio *cfg, uint8_t val)
{
	gpio_bit_write(cfg->gpioPeriph, cfg->pin, val);
}

/* get GPIO pin input status */
uint8_t gpioGetInput(tsCfgGpio *cfg)
{
	return gpio_input_bit_get(cfg->gpioPeriph, cfg->pin);
}

/* get GPIO pin output status */
uint8_t gpioGetOutput(tsCfgGpio *cfg)
{
	return gpio_output_bit_get(cfg->gpioPeriph, cfg->pin);
}

/* toggle GPIO pin status */
void gpioToggle(tsCfgGpio *cfg)
{
	gpio_bit_toggle(cfg->gpioPeriph, cfg->pin);
}


